<template>
  <div>
    <el-form
      ref="userForm"
      :model="userInfo"
      label-width="120px"
      style="margin-left: 120px; margin-top: 30px"
    >
      <el-form-item label="姓名:">
        <el-input v-model="userInfo.username" style="width:300px" />
      </el-form-item>
      <el-form-item label="密码:">
        <el-input v-model="userInfo.password" type="text" style="width:300px" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">更新</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getUserDetailById, setUserDetailById } from '@/api/employees'
export default {
  props: {
    // infoObj: {
    //   type: Object,
    //   required: true
    // }
  },
  data() {
    return {
      userId: this.$route.query.id,
      userInfo: {
        username: '',
        password: ''
      }
    }
  },
  created() {

  },
  mounted() {
    this.getUserDetail()
  },
  methods: {
    async getUserDetail() {
      const res = await getUserDetailById(this.userId)
      console.log(res)
      this.userInfo = res.data.data
    },
    async onSubmit() {
      try {
        const res = await setUserDetailById(this.userId, this.userInfo)
        console.log(res)
        if (res.data.success === true) {
          this.$message.success(res.data.message)
          this.userInfo = res.data.data
        }
      } catch (error) {
        this.$message.error(error.message)
      }
    }
  }
}
</script>

<style scoped>

</style>
